package com.guldan.thrall.web.controller;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.response.ResponseJson;
import com.guldan.jaina.dto.gauthority.GAuthorityDTO;
import com.guldan.jaina.dto.gauthority.GRoleAuthSaveDTO;
import com.guldan.jaina.dto.grole.GRoleSearchDTO;
import com.guldan.jaina.provider.IAuthorityProvider;
import com.guldan.thrall.common.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Silas.
 * Date: 2016/11/16
 * Time: 23:55
 */
@Controller
@RequestMapping("/authority")
public class AuthorityController extends BaseController {

    @Autowired
    private IAuthorityProvider iAuthorityProvider;

    //获取所有权限菜单，返回树形结构
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<GAuthorityDTO> list() {
        ResponseDTO<List<GAuthorityDTO>> response = iAuthorityProvider.listAllAuthority();
        return response.getData();
    }

    //通过角色id，返回树形结构权限菜单
    @RequestMapping(value = "/getByRoleId", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<GAuthorityDTO> getByRoleId(@RequestBody GRoleSearchDTO dto) {
        ResponseDTO<List<GAuthorityDTO>> response = iAuthorityProvider.getAuthorityByRoleId(dto.getId());
        return response.getData();
    }

    //修改某个角色用户的权限列表
    @RequestMapping(value = "/saveByRoleId", method = RequestMethod.POST)
    @ResponseJson
    public
    @ResponseBody
    List<GAuthorityDTO> saveByRoleId(@RequestBody GRoleAuthSaveDTO dto) {
        ResponseDTO<List<GAuthorityDTO>> response = iAuthorityProvider.saveAuthByRoleId(dto);
        return response.getData();
    }

}
